<template>
  <div>
    <el-button type="success" @click="dialogVisibility = true"
      >新增供应商</el-button
    >
    <el-dialog :visible.sync="dialogVisibility">
      <el-form
        ref="distributorEntity"
        class="distributorEntity"
        :model="distributorEntity"
        :rules="rules"
        label-position="right"
        label-width="auto"
      >
        <el-form-item prop="companyName" label="公司名称：">
          <el-input v-model.trim="distributorEntity.companyName"> </el-input>
        </el-form-item>

        <el-form-item prop="companyAddress" label="公司地址：">
          <el-input v-model="distributorEntity.companyAddress"> </el-input>
        </el-form-item>
        <el-form-item prop="phoneNumber" label="联系方式：">
          <el-input v-model="distributorEntity.phoneNumber"> </el-input>
        </el-form-item>
        <el-form-item prop="supplyDescr" label="经营范围：">
          <el-input v-model="distributorEntity.supplyDescr"> </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click="distributorEntitySubmit()"
            >提交
          </el-button>
          <el-button
            type="warning"
            icon="el-icon-remove"
            @click="() => $refs.distributorEntity.resetFields()"
            >重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// import New from './components/New.vue';
import { commodityModuleApi } from "@/api/apis";
export default {
  name: "InsertDistributor",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      dialogVisibility: false,
      distributorEntity: {
        companyName: null,
        companyAddress: null,
        phoneNumber: null,
        supplyDescr: null,

        isDeleted: true,
        distributorId: 0,
        distributorCode: null,
        creditLevel: 0,
      },
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },
  created() {},
  mounted() {},
  methods: {
    sampleM() {},
    distributorEntitySubmit() {
      // this.$http({
      //   method: "post",
      //   url: "/",
      //   data: this.distributorEntity,
      // })
      commodityModuleApi.distributorInsertApi(this.distributorEntity)
      .then(
        (res) => {
          this.$message.warning(JSON.stringify(res.data));
          if (res.data){
            this.dialogVisibility = false;
            this.$emit("postInsert")
          } ;
        },
        (error) => {
          console.log(
            ".distributorEntity request error : " + error.response.status
          );
        }
      );
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
